package com.vmj.rtda;

import com.vmj.heap.Method;

/**
 * Created by yangshoujun on 2017/8/12 上午11:53.
 */
public class Frame {

    LocalVars localVars;
    OperandStack operandStack;
    Thread thread;
    int nextPc;
    Method method;

    private boolean hasHappenException;

    public Frame(int maxLocalVars, int maxStack) {
        localVars = new LocalVars(maxLocalVars);
        operandStack = new OperandStack(maxStack);
    }

    public Frame(Thread thread, Method method) {
        this.method = method;
        this.thread = thread;
        localVars = new LocalVars(method.getMaxLocals());
        operandStack = new OperandStack(method.getMaxStack());
    }

    public Frame(Thread thread, Method method, OperandStack stack) {
        this.method = method;
        this.thread = thread;
        operandStack = stack;
    }

    public LocalVars getLocalVars() {
        return localVars;
    }

    public OperandStack getOperandStack() {
        return operandStack;
    }

    public void revertNextPc() {
        this.nextPc = this.thread.pc;
    }

    public void setLocalVars(LocalVars localVars) {
        this.localVars = localVars;
    }

    public void setOperandStack(OperandStack operandStack) {
        this.operandStack = operandStack;
    }

    public Thread getThread() {
        return thread;
    }

    public void setThread(Thread thread) {
        this.thread = thread;
    }

    public int getNextPc() {
        return nextPc;
    }

    public void setNextPc(int nextPc) {
        this.nextPc = nextPc;
    }

    public Method getMethod() {
        return method;
    }

    @Override
    public String toString() {
        return method.toString();
    }

    public boolean isHasHappenException() {
        return hasHappenException;
    }

    public void setHasHappenException(boolean hasHappenException) {
        this.hasHappenException = hasHappenException;
    }
}
